package com.leonzhangxf.guice.bill.domain;

import com.leonzhangxf.guice.bill.UnreachableException;

/**
 * The credit card.
 *
 * @author leonzhangxf
 */
public class CreditCard {

    private String cardNumber;

    private Integer amount;

    private Integer date;

    public CreditCard(String cardNumber, Integer amount, Integer date) {
        this.cardNumber = cardNumber;
        this.amount = amount;
        this.date = date;
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public Integer getAmount() {
        return amount;
    }

    public Integer getDate() {
        return date;
    }

    @Override
    public String toString() {
        return "CreditCard{" +
            "cardNumber='" + cardNumber + '\'' +
            ", amount=" + amount +
            ", date=" + date +
            '}';
    }

    public void charge(Integer amount) throws UnreachableException {
        if (this.amount < amount) {
            throw new UnreachableException("No enough money");
        }
        this.amount -= amount;
    }
}
